package com.example.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Resource
    private JwtInterceptor jwtInterceptor;
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer){
        configurer.addPathPrefix("/zcy",clazz->clazz.isAnnotationPresent(RestController.class));
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/zcy/**")
                .excludePathPatterns("/zcy/admin/login")
                .excludePathPatterns("/zcy/admin/register")
                .excludePathPatterns("/zcy/files/**")
                .excludePathPatterns("/zcy/type/upload")
                .excludePathPatterns("/zcy/paper/upload")
                .excludePathPatterns("/zcy/captcha")
                .excludePathPatterns("/zcy/ai");
    }
}
